aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/(app)/send/bitcoin/[address]/+layout.server.ts')
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/+layout.server.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
index 68191311..a321ec43 100644
--- a/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
+++ b/src/routes/(app)/send/bitcoin/[address]/+layout.server.ts
@@ -4,20 +4,22 @@ import { redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
const { user } = await parent();
const aid = cookies.get("aid");
- const { address } = params;
+ const { address, amount } = params;
const { balance } = await get(`/account/${aid}`, auth(cookies));
+ let invoice;
try {
- const invoice = await get(`/invoice/${address}`);
-
- if (invoice) {
- const recipient = await get(`/users/${invoice.uid}`);
- if (recipient?.id !== user.id)
- redirect(307, `/pay/${recipient.username}`);
- }
+ invoice = await get(`/invoice/${address}`);
} catch (e) {
// invoice not found
}
+ if (invoice) {
+ const recipient = await get(`/users/${invoice.uid}`);
+ let r = `/pay/${recipient.username}`;
+ if (amount) r += `/${amount}`;
+ if (recipient?.id !== user.id) redirect(307, r);
+ }
+
return { balance };
}